package com.woniu.project.controller;


import com.woniu.project.core.dto.ResultDto;
import com.woniu.project.core.exception.ProjectProductException;
import com.woniu.project.service.IImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WHF
 * @since 2020-10-13
 */
@RestController
@RequestMapping("/image")
@Api(tags = "image控制层")
public class ImageController {

    @Autowired
    private IImageService imageService;

    /**
     * 上传图片到服务器
     * @param file 图片文件
     * @return
     */
    @ApiOperation(value = "图片上传",notes = "无")
    @PostMapping("/iconUpload")
    public ResultDto iconUpload(MultipartFile file) {
        try {
            String addr = imageService.iconUpload(file);
            return ResultDto.success(200, "图片上传成功", addr);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ProjectProductException(500, "图片上传系统异常");
        }
    }
}

